#pragma once

#include <stdio.h>
#include <string>
#include <mutex>

class TransFile
{
public:
	TransFile();

	int start_download(const char* url, const char* localPath);
	int start_upload(const char* url, const char* localPath, const char* user = NULL, const char* pwd = NULL);
	void stop();
	static int FtpUpload(const char *localPath, const char *ftpPath, const char *user, const char *pwd);

private:
	static size_t CallBack_write(char *buffer, size_t size, size_t nitems, void* outstream);
	size_t write(char *buffer, size_t size, size_t nitems);

	static size_t CallBack_read(char *buffer, size_t size, size_t nitems, void *instream);
	size_t read(char *buffer, size_t size, size_t nitems);

	static int CallBack_process(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow);
	virtual int process(double dltotal, double dlnow, double ultotal, double ulnow);

private:
	FILE*		_fp;
	int			_trans_direct;
	bool		_run;
	long		_file_len;
	std::string _file_name;
	static std::mutex	_mtx;
	static bool			_init;
};

